<html>
<head> <title> Purchase Page</title></head>
<body>
<? 
include_once("config/config.php");
include_once("config/functions.php");
// Step One: Enter Steam ID, Step Two: Choose Server, Step Three: Choose Item, Step Four: Bring person to paypal and await IPN request
if(isset($_POST['LoggedIn']) && !empty($_POST['LoggedIn'])){
	//Steamid or not
	$Step = 2;
}else{
	// normal if not set
	$Step = 1;
}
if($Step == 1){
	//Entry for steam id. the actionm method and names should no tbe changed
	echo '<form action="index.php" method="post">
	Steam ID: <input type="text" name="LoggedIn">
	<br />
	<input type="submit" name="Submit">
	</form>';
}elseif($Step == 2){
//Connect
	$database = new PDO('mysql:host='.$Config['database_host'].';dbname='.$Config['database_name'], $Config['database_user'], $Config['database_password']);
	//Send query
	$query = $database->query("SELECT `".$Config['table_prefix']."main`.`steamid`, `".$Config['table_prefix']."main`.`group` FROM `main`");
	//Get the id passed
	$ID = $_POST['LoggedIn'];
	//GEt joined players table. This query will be change, as it is very resource intesive.
	while ($row = $query->fetch(PDO::FETCH_ASSOC)){
		if($row['steamid'] != $ID){
			// if not found, it will set false
			$match = false;
		}else{
		//fi found it will true then it will berak the loop
			$match = true;
			break;
		}
	}
	//Gets the community id, then querys the stea, api, then return the info
	if($match){
		//Echo out the steamid above the picture.
		echo 'Is '.$ID.' yours?<br />';
		//Get comid, to get the api request
		$ComID = getFriendId($ID);
		//Do api
		$response = file_get_contents('http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=' . $Config['SteamAPIKey'] . '&steamids=' . $ComID);
		$profileInfo = json_decode($response, true);
		//Image of profile picture
		echo '<a href="http://steamcommunity.com/profiles/'.$ComID.'"  target="_blank" ><img src="'.$profileInfo['response']['players'][0]['avatarfull'].'" ></a><br />';
		//User name, you can change this around a tad
		echo 'Username: '.$profileInfo['response']['players'][0]['personaname'].' <br />';
	}else{
		//If not found.
		echo 'This SteamID has never connected!';
		//Stops code from this point on.
		exit();
	}
		
}
?>

</body>
</html>